<?php
/**
 * @ClassName: Agent
 * @Description: TODO
 * @author: gydtrade
 * @Date: 2025-10-20 18:56
 * @Version: V1.0.0
 */

namespace app\test\controller;

use app\common\model;
use think\Controller;

class Agent extends Controller
{

    /**
     * 批量重置密码
     * @return \think\response\Json
     */
    function batchSetPassword()
    {
        $list = model\Agent::select();
        $default_password = env('default_password');
        $count = 0;
        foreach ($list as &$agent) {
            $arr = passCrypt($default_password);
            $agent['password'] = $arr[0];
            $agent['salt'] = $arr[1];
            $agent['super_pass'] = passEncryp($arr[1]);

            $res = $agent->save();
            if ($res) {
                $count++;
            }
        }

        return json(['code' => 1, 'msg' => '共' . count($list) . '条数据，修改成功' . $count . '条']);
    }

}